<?php
namespace app\api\model;

use think\Model;
use think\Db;
class TrainModel extends Model
{
       function trainlist(){
           $result=Db::name('train')->select();
           return $result;
       }
    function traindetail($rid){
        $result= Db::name('train')->where('trainid',$rid)->find();
        return  $result;

    }
    function posttrain($userid,$trainid){
         $data=[
             'userid'=>$userid,
             'trainid'=>$trainid,
             'createtime'=>date("YmdHis")
         ];
        $num=Db::name("train_enroll")->where("userid='$userid'")->where("trainid='$trainid'")->count();
        if ($num) {

            return 1;
        }  else
        {
            $res=Db::name("train_enroll")->insert($data);
            if($res){

                return 2;

            }else{
                return 3;
            }
        }


    }
}